package com.abl.core.common.util.coll;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class ArrayKit {
    /**
     * 切分数组
     *
     * @param collection 被切分的数组 [1,2,3,4,5]
     * @param size       长度
     * @param <R>        数组泛型
     * @return 切分后的数组 [[1,2],[3,4],[5]]
     */
    public static <R> ArrayList<ArrayList<R>> split(Collection<R> collection, int size) {
        ArrayList<R> list = new ArrayList<>(collection);
        if (list.size() == 0) return new ArrayList<>();
        ArrayList<ArrayList<R>> arrayLists = new ArrayList<>();
        arrayLists.add(new ArrayList<>(list));
        if (size == 0) return arrayLists;
        ArrayList<ArrayList<R>> objects = new ArrayList<>();
        int cycleCount = list.size() / size;

        for (int i = 0; i < cycleCount; i++) {
            List<R> rs = list.subList(i * size, (i + 1) * size);
            objects.add(new ArrayList<>(rs));
        }
        int yu = list.size() % size;
        if (yu > 0) {
            List<R> rs = list.subList(cycleCount * size, (cycleCount * size) + yu);
            objects.add(new ArrayList<>(rs));
        }
        return objects;
    }

    //大于0返回true；否则返回false
    public static boolean geZero(Collection<?> collection) {
        return collection != null && collection.size() > 0;
    }

    public static boolean isNotBlank(Collection<?> collection) {
        return collection != null && collection.size() != 0;
    }

    public static boolean isBlank(Collection<?> collection) {
        return !isNotBlank(collection);
    }

    public static boolean isNotBlank(Object... values) {
        return values != null && values.length != 0;
    }

    public static boolean isBlank(Object... values) {
        return !isNotBlank(values);
    }

//    public static void main(String[] args) {
//        List<Integer> integers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
//        System.out.println(split(integers, 1));
//        System.out.println(split(integers, 1).size());
//        System.out.println();
//        System.out.println(split(integers, 2));
//        System.out.println(split(integers, 2).size());
//        System.out.println();
//
//        System.out.println(split(integers, 3));
//        System.out.println(split(integers, 3).size());
//        System.out.println();
//
//        System.out.println(split(integers, 4));
//        System.out.println(split(integers, 4).size());
//        System.out.println();
//
//        System.out.println(split(integers, 5));
//        System.out.println(split(integers, 5).size());
//        System.out.println();
//
//        System.out.println(split(integers, 6));
//        System.out.println(split(integers, 6).size());
//        System.out.println();
//
//        System.out.println(split(integers, 7));
//        System.out.println(split(integers, 7).size());
//        System.out.println();
//
//        System.out.println(split(integers, 8));
//        System.out.println(split(integers, 8).size());
//        System.out.println();
//
//        System.out.println(split(integers, 9));
//        System.out.println(split(integers, 9).size());
//        System.out.println();
//
//        System.out.println(split(integers, 10));
//        System.out.println(split(integers, 10).size());
//        System.out.println();
//
//        System.out.println(split(integers, 11));
//        System.out.println(split(integers, 11).size());
//        System.out.println();
//
//        System.out.println(split(integers, 12));
//        System.out.println(split(integers, 12).size());
//        System.out.println();
//
//        System.out.println(split(integers, 13));
//        System.out.println(split(integers, 13).size());
//        System.out.println();
//
//    }
}
